package net.deuce.perf;

import net.deuce.rc.client.RemoteCommand;
import net.deuce.rc.client.RemoteCommandClient;
import net.deuce.rc.client.RemoteBackgroundCommand;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.BeanNameAware;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.LinkedList;
import java.util.List;

public class AppServerConfiguration implements InitializingBean, BeanNameAware {
    private String name;
    private List<RunCommandWrapper> startCommands = new LinkedList<RunCommandWrapper>();
    private List<RemoteBackgroundCommand> logs = new LinkedList<RemoteBackgroundCommand>();
    private RemoteCommandClient remoteCommandClient;

    private Log log = LogFactory.getLog(getClass());

    public AppServerConfiguration() {
        //log.trace("");
    }
    
    public String getName() {
        //log.trace("");
        return name;
    }

    public void setName(String name) {
        //log.trace("");
        this.name = name;
    }

    public List<RunCommandWrapper> getStartCommands() {
        //log.trace("");
        return startCommands;
    }

    public void setStartCommands(List<RunCommandWrapper> startCommands) {
        //log.trace("");
        this.startCommands = startCommands;
    }

    public void addStartCommand(RunCommandWrapper startCommand) {
        //log.trace("");
        startCommands.add(startCommand);
    }

    public List<RemoteBackgroundCommand> getLogs() {
        //log.trace("");
        return logs;
    }

    public void setLogs(List<RemoteBackgroundCommand> logs) {
        //log.trace("");
        this.logs = logs;
    }

    public void addLog(RemoteBackgroundCommand log) {
        this.//log.trace("");
        logs.add(log);
    }

    public void afterPropertiesSet() throws Exception {
        //log.trace("");
        for (RemoteCommand rc : startCommands) {
            rc.setRemoteCommandClient(remoteCommandClient);
        }
        for (RemoteCommand rc : logs) {
            rc.setRemoteCommandClient(remoteCommandClient);
        }
    }

    public void setRemoteCommandClient(RemoteCommandClient remoteCommandClient) {
        //log.trace("");
        this.remoteCommandClient = remoteCommandClient;
    }

    public RemoteCommandClient getRemoteCommandClient() {
        //log.trace("");
        return remoteCommandClient;
    }

    public void setBeanName(String s) {
        setName(s);
    }
}
